<html>
<head>
<script src="../LayoutTests/fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("Test to verify that serial allocation and dereferencing of large canvases will succeed");
// This is a manual test because it runs too slow as a LayoutTest, especially for GPU tests with mesa.

// 32 canvases of 8k x 8k will consume 8GB of RAM.
// Garbage collection should kick-in to prevent OOM failures.
for (var i = 0; i < 32; i++) {
    var canvas = document.createElement('canvas');
    canvas.width = 8192;
    canvas.height = 8192;
    // Draw to trigger lazy backing store allocation
    var ctx = canvas.getContext('2d');
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, 1, 1);
    // Verify that allocation succeeded by verifying that draw succeeded
    var imageData = ctx.getImageData(0, 0, 1, 1);
    var imgdata = imageData.data;
    shouldBe("imgdata[0]", "0");
    shouldBe("imgdata[1]", "255");
    shouldBe("imgdata[2]", "0");
}
</script>
<script src="../LayoutTests/fast/js/resources/js-test-post.js"></script>
</body>
</html>
